using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Memory;
using SemanticKernelBlazorDemo.Core.Utils;

namespace SemanticKernelBlazorDemo.Core;

public class KernelProvider : IKernelProvider {
    public IKernel GetKernel(ILogger<IKernel> logger) =>
        new KernelBuilder().WithLogger(logger).Configure(p => {
            p.AddAzureTextCompletionService(
                ProjectEnvironment.Get("AzureOpenAIDeploymentName"),
                ProjectEnvironment.Get("AzureOpenAIEndpoint"),
                ProjectEnvironment.Get("AzureOpenAIKey"),
                ProjectEnvironment.Get("AzureOpenAIServiceId"));

            p.AddAzureTextEmbeddingGenerationService(
                ProjectEnvironment.Get("AzureOpenAIEmbeddingsDeploymentName"),
                ProjectEnvironment.Get("AzureOpenAIEmbeddingsEndpoint"),
                ProjectEnvironment.Get("AzureOpenAIEmbeddingsKey"),
                ProjectEnvironment.Get("AzureOpenAIEmbeddingsServiceId"));
        }).WithMemoryStorage(new VolatileMemoryStore()).Build();
}